﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Vehicle.Web.Pages.Transit
{
    /// <summary>
    /// Copyright (C) M-Tear团队
    /// 文 件 名：Transit_Task.aspx.cs
    /// 版    本：v1.00.0000
    /// 创建标识：2009-08-31   Created by 杨光远 V1.00.0000
    /// 功能说明：历史承运任务查询页面类
    /// 注意事项：无
    /// 
    /// 更新记录：
    /// 
    /// </summary>
    public partial class Transit_Task : Component.PageBase
    {
        #region---基本变了实例化---
        BLL.Cargo b_Cargo = new Vehicle.BLL.Cargo();
        Model.ComponentsInfo m_ComponentsInfo = new Vehicle.Model.ComponentsInfo();
        public string onshow;//定义没有数据时页面的显示内容
        #endregion

        #region---基本操作---
        /// <summary>
        /// 数据加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CargoDataBind();
            }
        }
        /// <summary>
        /// 数据绑定
        /// </summary>
        public void CargoDataBind()
        {
            if (rbt_C_Time.Checked)//按添加时间
            {
                m_ComponentsInfo.startIndex = 0;//当前页的起始索引
                m_ComponentsInfo.endIndex = b_Cargo.GetAllSearchCount(new Model.ComponentsInfo("Cargo", drop_C_Receive.SelectedValue == "0" ? "1" : "C_Receive", drop_C_Receive.SelectedValue == "0" ? "1" : drop_C_Receive.SelectedValue, "1", "1", "C_IsDelete", "1", "C_Time", Vehicle.Common.TextHelper.StringToDateTime(this.Gmdp_Start.DateString), Vehicle.Common.TextHelper.StringToDateTime(this.Gmdp_End.DateString), "C_ID"));//当前页的结束索引
                m_ComponentsInfo.tableName = "Cargo";//表名
                m_ComponentsInfo.condition = drop_C_Receive.SelectedValue == "0" ? "1" : "C_Receive";//条件一
                m_ComponentsInfo.result = drop_C_Receive.SelectedValue == "0" ? "1" : drop_C_Receive.SelectedValue;//匹配结果一
                m_ComponentsInfo.Tcondition = "1";//条件二
                m_ComponentsInfo.Tresult = "1";//匹配结果二
                m_ComponentsInfo.Scondition = "C_IsDelete";//条件三
                m_ComponentsInfo.Sresult = "1";//匹配结果三
                m_ComponentsInfo.Count = "C_Time";//时间
                m_ComponentsInfo.order = "C_ID";//排序
                if (Gmdp_Start.Date != null)//判断起始时间是否为空
                {
                    m_ComponentsInfo.StartTime = Vehicle.Common.TextHelper.StringToDateTime(this.Gmdp_Start.DateString);
                }
                if (Gmdp_End.Date != null)//判断结束时间是否为空
                {
                    m_ComponentsInfo.EndTime = Vehicle.Common.TextHelper.StringToDateTime(this.Gmdp_End.DateString);
                }
                ReptShow.DataSource = b_Cargo.GetAllSearch(m_ComponentsInfo).DefaultView;
                ReptShow.DataBind();
            }
            else if (rbt_C_Contact.Checked)//客户姓名
            {
                ReptShow.DataSource = b_Cargo.GetModel(new Vehicle.Model.ComponentsInfo("Cargo", "C_Contact", txt_C_Contact.Text.Trim(), drop_C_Receive.SelectedValue == "0" ? "1" : "C_Receive", drop_C_Receive.SelectedValue == "0" ? "1" : drop_C_Receive.SelectedValue, "C_IsDelete", "1", "C_ID")).DefaultView;
                ReptShow.DataBind();
            }
            else if (rbt_C_contract.Checked)//合同号查询
            {
                ReptShow.DataSource = b_Cargo.GetModel(new Vehicle.Model.ComponentsInfo("Cargo", "C_contract", txt_C_contract.Text.Trim(), drop_C_Receive.SelectedValue == "0" ? "1" : "C_Receive", drop_C_Receive.SelectedValue == "0" ? "1" : drop_C_Receive.SelectedValue, "C_IsDelete", "1", "C_ID")).DefaultView;
                ReptShow.DataBind();
            }
            else if (rbt_C_Card.Checked)//承运单编号查询
            {
                ReptShow.DataSource = b_Cargo.GetModel(new Vehicle.Model.ComponentsInfo("Cargo", "C_Card", txt_C_Card.Text.Trim(), drop_C_Receive.SelectedValue == "0" ? "1" : "C_Receive", drop_C_Receive.SelectedValue == "0" ? "1" : drop_C_Receive.SelectedValue, "C_IsDelete", "1", "C_ID")).DefaultView;
                ReptShow.DataBind();
            }
            if (ReptShow.Items.Count == 0)//判断没有数据时页面的显示内容
            {
                onshow = "当前页面无数据";
            }
            else
            {
                onshow = "";
            }
        }
        /// <summary>
        /// 导出EXCEL事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Excel_Click(object sender, EventArgs e)
        {
            DataTable2Excel();
        }
        /// <summary>
        /// 查询按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Select_Click(object sender, EventArgs e)
        {
            CargoDataBind();
        }
        /// <summary>
        /// 导出EXCEL文件
        /// </summary>
        /// <param name="dtData"></param>
        public void DataTable2Excel()
        {
            if (ReptShow.Items.Count > 0)
            {
            // 当前对话
            System.Web.HttpContext curContext = System.Web.HttpContext.Current;
            // IO用于导出并返回excel文件
            System.IO.StringWriter strWriter = null;
            System.Web.UI.HtmlTextWriter htmlWriter = null;
            curContext.Response.ContentType = "application/vnd.ms-excel";
            curContext.Response.ContentEncoding = System.Text.Encoding.Default;
            curContext.Response.Charset = "";
            strWriter = new System.IO.StringWriter();
            htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);
            // 返回客户端
            ReptShow.RenderControl(htmlWriter);
            curContext.Response.Write(strWriter.ToString());
            curContext.Response.End();
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(UPanel, this.GetType(), "click", "alert('当前页面无数据,无法导出!')", true);
            }
        }
        /// <summary>
        /// Datalist数据绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ReptShow_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {

                Label lab_C_Receive = (Label)e.Item.FindControl("lab_C_Receive");//更改接收情况
                switch (lab_C_Receive.Text)
                {
                    case "1": lab_C_Receive.Text = "是"; break;
                    case "2": lab_C_Receive.Text = "否"; break;
                    case "3": lab_C_Receive.Text = "审核中"; break;
                }
                Label lab_C_Result = (Label)e.Item.FindControl("lab_C_Result");//更改完成情况
                switch (lab_C_Result.Text)
                {
                    case "1": lab_C_Result.Text = "运输中"; break;
                    case "2": lab_C_Result.Text = "已完成"; break;
                    case "3": lab_C_Result.Text = "失败"; break;
                    case "4": lab_C_Result.Text = "审核中"; break;
                }
            }
        }
        #endregion
    }
}
